package com.example.houseman.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.houseman.entity.TCfContract;
import com.example.houseman.service.ITCfContractService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.org.dto.ContractDto;
import com.org.vo.ResultEntity;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 龚梦
 * @since 2021-03-30
 */
@RestController
@Slf4j
@RequestMapping("/hou/tcfContractController")
public class TCfContractController {


    @Autowired
    private ITCfContractService ITCfContractService;


    @RequestMapping("selects")
    public ResultEntity selects(ContractDto contractDto) {
        log.info("===================" + contractDto);
        PageHelper.startPage(contractDto.getPageNum(), contractDto.getPageSize());
        QueryWrapper<TCfContract> wrapper = new QueryWrapper<>();
        if (contractDto.getTenantName() != null) {
            wrapper.like("tenant_name", contractDto.getTenantName());
        }
        if (contractDto.getTenantPhone() != null) {
            wrapper.like("tenant_phone", contractDto.getTenantPhone());
        }
        if (contractDto.getSignType() != null) {
            wrapper.like("sign_type", contractDto.getSignType());
        }
        if (contractDto.getPremiseName() != null) {
            wrapper.like("premise_name", contractDto.getPremiseName());
        }
        if (contractDto.getStartDate() != null) {
            wrapper.eq("start_date", contractDto.getStartDate());
        }
        if (contractDto.getCfContractNo() != null) {
            wrapper.like("cf_contract_no", contractDto.getCfContractNo());
        }
        if (contractDto.getT1() != null) {
            wrapper.lt("input_date", contractDto.getT1());
        }
        if (contractDto.getT2() != null) {
            wrapper.ge("input_date", contractDto.getT2());
        }
        List<TCfContract> list = ITCfContractService.list(wrapper);
        PageInfo<TCfContract> info = new PageInfo<>(list);
        return ResultEntity.ok("200", "查询成功", info);
    }

}
